﻿using Core.Domain;
using Library.Helpers;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Core.Dtos
{
    public static class IDictionaryItemExtensions
    {
        public static int GetId(this IEnumerable<IDictionaryItem> list, string name)
        {
            return list.Where(x => x.Name.Equals(name)).First().Id;
        }

        public static int GetId<TEnum>(this IEnumerable<IDictionaryItem> list, TEnum name)
        {
            return list.GetId(name.ToString());
        }

        public static string GetName(this IEnumerable<IDictionaryItem> list, int id)
        {
            return list.Where(x => x.Id.Equals(id)).First().Name;
        }

        public static TEnum GetName<TEnum>(this IEnumerable<IDictionaryItem> list, int id)
        {
            return EnumHelper<TEnum>.ToEnum(list.GetName(id));
        }

        public static IEnumerable<IDictionaryItem> FindBy(this IEnumerable<IDictionaryItem> list, DictionaryName dictionary)
        {
            string dictionaryName = dictionary.ToString();
            return list.FindBy(dictionaryName);
        }

        public static IEnumerable<IDictionaryItem> FindBy(this IEnumerable<IDictionaryItem> list, string dictionaryName)
        {         
            return list.Where(x => x.DictionaryName.Equals(dictionaryName));
        }
    }
}
